package com.example.mapper;

import com.example.entity.ClubApplication;
import com.example.entity.Clubmember;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ClubApplicationMapper {
    @Select("select ca.*,s.name as studentName from club_application ca left join student s on ca.student_id = s.id where club_id = #{clubId}")
    List<ClubApplication> selectByClubId(Integer clubId);

    @Select("SELECT ca.id, ca.club_id as clubId, ca.student_id as studentId, " +
            "ca.apply_time as applyTime, ca.status, " +
            "s.name as studentName, c.name as clubName " +
            "FROM club_application ca " +
            "LEFT JOIN student s ON ca.student_id = s.id " +
            "LEFT JOIN club c ON ca.club_id = c.id " +
            "ORDER BY ca.apply_time DESC")
    List<ClubApplication> selectAll();

    @Select("SELECT ca.id, ca.club_id as clubId, ca.student_id as studentId, " +
            "ca.apply_time as applyTime, ca.status, " +
            "s.name as studentName, c.name as clubName " +
            "FROM club_application ca " +
            "LEFT JOIN student s ON ca.student_id = s.id " +
            "LEFT JOIN club c ON ca.club_id = c.id " +
            "WHERE ca.id = #{id}")
    ClubApplication selectById(Integer id);

    @Update("UPDATE club_application SET status = #{status} WHERE id = #{id}")
    void updateStatus(@Param("id") Integer id, @Param("status") String status);

    @Insert("INSERT INTO club_application (club_id, student_id, apply_time, status) " +
            "VALUES (#{clubId}, #{studentId}, #{applyTime}, #{status})")
    int insert(ClubApplication application);

    @Select("select ca.*,s.name as studentName from club_application ca left join student s on ca.student_id = s.id where club_id = #{clubId}")
    List<ClubApplication> getByCludId(Integer clubId);

    List<ClubApplication> getByCondition(ClubApplication param);
}